package com.ss.android.newmedia.b;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import com.bytedance.article.common.c.TTUtils;

import java.util.Iterator;

public final class c extends a {
    public c() {

    }

    public final String a() {
        return "open_uc";
    }

    public final boolean a(Context arg11, String arg12) {
        int v0_5;
        String v7_2;
        boolean v0_3;
        String v0_2;
        Object v0_1;
        String v3;
        String v4 = null;
        if (arg11 != null && arg12 != null && (TTUtils.isValidUrl(arg12))) {
            PackageManager v5 = arg11.getPackageManager();
            String v6 = arg11.getPackageName();
            try {
                v3 = "com.UCMobile.intent.action.LOADURL";
                Iterator v7 = v5.queryIntentActivities(new Intent(v3), 65600).iterator();
                do {
                    if (v7.hasNext()) {
                        v0_1 = v7.next();
                        if (v0_1 == null) {
                            break;
                        } else if (((ResolveInfo) v0_1).activityInfo != null) {
                            v0_2 = ((ResolveInfo) v0_1).activityInfo.packageName;
                        } else {
                            break;
                        }
                        if (v0_2 == null) {
                            continue;
                        }

                        if (v0_2.length() == 0) {
                            continue;
                        }

                        if (!v0_2.toLowerCase().contains("uc")) {
                            continue;
                        }

                        Intent v7_1 = new Intent(v3);
                        v7_1.putExtra("UC_LOADURL", arg12);
                        v7_1.putExtra("pd", "addon:" + v6);
                        v7_1.setPackage(v0_2);
                        v7_1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        arg11.startActivity(v7_1);
                        v0_3 = true;
                        return v0_3;
                    } else {
                        label_50:
                        v7_2 = "com.uc.browser.intent.action.LOADURL";
                        Iterator v8 = v5.queryIntentActivities(new Intent(v7_2), 65600).iterator();
                        do {
                            label_56:
                            if (!v8.hasNext()) {
                                return false;
                            }

                            v0_1 = v8.next();
                            if (v0_1 == null) {
                                break;
                            } else if (((ResolveInfo) v0_1).activityInfo != null) {
                                v3 = ((ResolveInfo) v0_1).activityInfo.packageName;
                            } else {
                                v3 = v4;
                            }

                            if (v3 == null) {
                                continue;
                            }

                            if (v3.length() == 0) {
                                continue;
                            }

                            if (!v3.toLowerCase().contains("uc")) {
                                continue;
                            }

                            PackageInfo v0_4 = v5.getPackageInfo(v3, 0);
                            if (v0_4 != null) {
                                v0_5 = v0_4.versionCode;
                            } else {
                                v0_5 = 0;
                            }
                            Intent v4_1 = new Intent(v7_2);
                            if (v0_5 < 30) {
                                v4_1.putExtra("UC_LOADURL", arg12);
                            } else {
                                v4_1.putExtra("UC_LOADURL", "ext:cm_page/" + arg12);
                            }

                            v4_1.putExtra("time_stamp", System.currentTimeMillis());
                            v4_1.putExtra("pd", "addon:" + v6);
                            v4_1.setPackage(v3);
                            v4_1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            arg11.startActivity(v4_1);
                            return true;
                        }
                        while (true);
                    }
                }
                while (true);
            } catch (Exception v0) {
                v0.printStackTrace();
            }
        }
        return false;
    }
}

